package com.yonyou.cyxdms.sysAuth.service.service.log.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yonyou.cyx.framework.util.bean.ApplicationContextHelper;
import com.yonyou.cyxdms.framework.bean.dto.user_info.LoginInfoDto;
import com.yonyou.cyxdms.sysAuth.service.entity.MenuOperateLogPO;
import com.yonyou.cyxdms.sysAuth.service.mapper.MenuOperateLogMapper;
import com.yonyou.cyxdms.sysAuth.service.service.log.MenuOperateLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;


/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author maxingjian
 * @since 2019-10-21
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class MenuOperateLogServiceImpl extends ServiceImpl<MenuOperateLogMapper, MenuOperateLogPO> implements MenuOperateLogService {
    //日志对象
    private static final Logger logger = LoggerFactory.getLogger(MenuOperateLogServiceImpl.class);
    @Autowired
    MenuOperateLogMapper menuOperateLogMapper;

    @Override
    public void recordLog(String menuId) {
        LoginInfoDto loginInfoDto = ApplicationContextHelper.getBeanByType(LoginInfoDto.class);
        MenuOperateLogPO menuoperatelogpo = new MenuOperateLogPO();
        menuoperatelogpo.setAppId(loginInfoDto.getAppId());
        menuoperatelogpo.setCompanyId(loginInfoDto.getCompanyId());
        menuoperatelogpo.setMenuId(Long.parseLong(menuId));
        menuoperatelogpo.setOperateDate(LocalDateTime.now());
        menuoperatelogpo.setOperator(loginInfoDto.getUserId());
        menuoperatelogpo.setOwnerCode(loginInfoDto.getOwnerCode());
        menuoperatelogpo.setUserOrgId(loginInfoDto.getUserOrgId());
        menuOperateLogMapper.insert(menuoperatelogpo);
    }
}
